/**
 * 记分牌
 */
class ScorePanel {
  /**
   * 分类
   */
  private _score: number
  /**
   * 等级
   */
  private _level: number
  /**
   * 最高等级
   */
  private maxLevel: number
  /**
   * 每多少分升级
   */
  private upScore: number

  /**
   * 分数元素
   */
  private scoreEle: HTMLElement
  /**
   * 等级元素
   */
  private levelEle: HTMLElement


  constructor(maxLevel: number = 10, upScore: number = 10) {
    this._score = 0
    this._level = 1
    this.maxLevel = maxLevel
    this.upScore = upScore
    this.scoreEle = document.getElementById("score")!
    this.levelEle = document.getElementById("level")!
  }

  get score() {
    return this._score
  }

  get level() {
    return this._level
  }

  /**
   * 加分
   */
  addScore(): void {
    // 分数自增加
    this.scoreEle.innerHTML = ++this._score + ''

    if (this._score % this.upScore === 0) {
      this.levelUp()
    }

  }

  /**
   * 等级提升
   */
  levelUp(): void {
    // 不能超过最大等级
    if (this._level < this.maxLevel) {
      this.levelEle.innerHTML = ++this._level + ''
    }
  }

}


export default ScorePanel